<?php


namespace App\Modules\Health\Http\Controllers\Api;


use App\Http\Controllers\Api\Controller;
use App\Modules\Health\Constants\AdvConfigConstant;
use App\Modules\Health\Services\ConfigService;

class ConfigsController extends Controller
{
    public function advConfig()
    {
        $miniType = $this->getMiniType();

        $memberId = auth('api')->user()->id ?? 0;

        if ($memberId) {
            $flag = isCloseAdv($memberId, $this->getMiniType());
        }

        if (isset($flag) && $flag) {
            $advConfig = [];
        } else {
            $advConfig = app(ConfigService::class)->getConfigs(AdvConfigConstant::GROUP);
            $advConfig = array_merge($advConfig, getMiniAdvIds($miniType));
        }

        $bannerConfig = app(ConfigService::class)->getConfigs(AdvConfigConstant::BANNER_GROUP);

        $data = [
            'banner'     => explode(',', $bannerConfig[AdvConfigConstant::BANNER_GROUP] ?? ''),
            'adv_config' => $advConfig,
        ];

        return $this->_success($data);
    }
}
